package dyyx;

import java.util.Properties;

import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.StandardEnvironment;

public class EnvTest {
	
	public static void main(String[] args) throws Exception {			
		StandardEnvironment env = new StandardEnvironment();
		
		System.out.println(env);
		System.out.println(env.getDefaultProfiles());
		System.out.println(env.getSystemEnvironment());
		System.out.println(env.getSystemProperties());
		MutablePropertySources mutablePropertySources = env.getPropertySources();
				
		Properties  properties1 = new Properties();
		properties1.put("name", "cat1");
		
		Properties  properties2 = new Properties();
		properties2.put("name", "cat2");
		
		PropertiesPropertySource pps1 = new PropertiesPropertySource("PropertiesPropertySource1",properties1);
		PropertiesPropertySource pps2 = new PropertiesPropertySource("PropertiesPropertySource2",properties2);
	
		// mutablePropertySources.addFirst(pps1);
		// mutablePropertySources.addFirst(pps2);
		
		mutablePropertySources.addLast(pps1);
		mutablePropertySources.addLast(pps2);
		
		System.out.println(env);
		
		// addFirst
		// StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[PropertiesPropertySource {name='PropertiesPropertySource2'}, PropertiesPropertySource {name='PropertiesPropertySource1'}, MapPropertySource {name='systemProperties'}, SystemEnvironmentPropertySource {name='systemEnvironment'}]}

		// addLast  注意顺序
		// StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[MapPropertySource {name='systemProperties'}, SystemEnvironmentPropertySource {name='systemEnvironment'}, PropertiesPropertySource {name='PropertiesPropertySource1'}, PropertiesPropertySource {name='PropertiesPropertySource2'}]}
	
		System.out.println(env.getSystemEnvironment().get("name"));
		// -Dname=name-in-jvm-args
		System.out.println(env.getSystemProperties().get("name"));
		System.out.println(env.getProperty("name"));	
	}
}
